# API测试脚本
# 用于测试日志功能

Write-Host "=== Spring AI Ollama Demo API 测试 ===" -ForegroundColor Green

$baseUrl = "http://localhost:8082/api/ollama"

Write-Host "`n1. 测试 GET /chat 接口" -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/chat?prompt=你好" -Method GET
    Write-Host "GET 响应: $response" -ForegroundColor Cyan
} catch {
    Write-Host "GET 请求失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n2. 测试 POST /chat 接口" -ForegroundColor Yellow
try {
    $body = @{
        prompt = "介绍一下Spring AI"
    } | ConvertTo-Json

    $response = Invoke-RestMethod -Uri "$baseUrl/chat" -Method POST -Body $body -ContentType "application/json"
    Write-Host "POST 响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor Cyan
} catch {
    Write-Host "POST 请求失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n3. 测试 POST /chat-with-system 接口" -ForegroundColor Yellow
try {
    $body = @{
        prompt = "今天天气怎么样？"
        systemMessage = "你是一个友善的天气助手。"
    } | ConvertTo-Json

    $response = Invoke-RestMethod -Uri "$baseUrl/chat-with-system" -Method POST -Body $body -ContentType "application/json"
    Write-Host "POST with System 响应: $($response | ConvertTo-Json -Depth 3)" -ForegroundColor Cyan
} catch {
    Write-Host "POST with System 请求失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n=== 测试完成 ===" -ForegroundColor Green
Write-Host "请检查应用控制台的日志输出" -ForegroundColor Magenta
